package com.ztjy.market.biz.impl;

import com.ztjy.bean.Custom;
import com.ztjy.market.biz.CustomBiz;
import com.ztjy.market.dao.CustomDao;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomBizImpl implements CustomBiz {
    @Autowired
    private CustomDao udao;


    @Override
    public List<Custom> findAllCustom(Custom custom) {
        return udao.findAllCustom(custom);
    }

    @Override
    public PageInfo<Custom> findCustomPage(Custom custom, Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        List<Custom> all = udao.findAll(custom);
        PageInfo<Custom> customPageInfo = new PageInfo<Custom>(all);
        return customPageInfo;
    }

    @Override
    public boolean updateCustom(Custom custom) {
        boolean flag = false;
        try {
            int row = udao.updateByPrimaryKeySelective(custom);
            flag = (row != 0) ? true : false;
        } catch (Exception ex) {
            ex.printStackTrace();
            flag = false;
        }
        return flag;
    }

    @Override
    public boolean addCustom(Custom custom) {
        boolean flag = false;
        try {
            int row = udao.insertSelective(custom);
            flag = (row != 0) ? true : false;
        } catch (Exception ex) {
            ex.printStackTrace();
            flag = false;
        }
        return flag;
    }

    @Override
    public Custom findByIdCustom(Integer id) {
        return udao.findByIdCustom(id);
    }

}
